package com.example.designpattern.responsibility;

import com.alibaba.nacos.common.utils.StringUtils;
import com.example.designpattern.responsibility.config.ValidatorEnum;
import com.example.model.GoodsDTO;
import com.example.util.ApplicationUtils;
import org.springframework.beans.factory.SmartInitializingSingleton;

/**
 * @author long
 * @date 2024/4/20 10:43
 */
public interface IValidator extends SmartInitializingSingleton {

    void validate(GoodsDTO dto);

    ValidatorEnum type();

    default IValidator getNextNode(){
        String nextNode = type().getNext();
        if(StringUtils.isNotBlank(nextNode)){
            return ApplicationUtils.getBeanByName(nextNode);
        }
        return null;
    }

    IValidator setNext(IValidator next);

}
